package cn.com.czpb.client.module.news.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.MediaNewsBean;

public class HListViewAdapterForSubscribe extends BaseAdapter{
    private Context mContext;
    private LayoutInflater mInflater;
    private List<MediaNewsBean> list;
    public HListViewAdapterForSubscribe(Context context, List<MediaNewsBean> list){
        this.mContext = context;
        this.list = list;
        mInflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//LayoutInflater.from(mContext);
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if(convertView==null){
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_news_subscribe_scroll, null);
            holder.cardview = convertView.findViewById(R.id.item_news_scroll_card);
            holder.mImage=(ImageView)convertView.findViewById(R.id.scrollitempic);
            holder.mTitle=(TextView)convertView.findViewById(R.id.item_news_scroll_title);
            holder.priasecount = (TextView) convertView.findViewById(R.id.scroll_item_praise_num);
            holder.fabutime = (TextView) convertView.findViewById(R.id.scroll_item_fabu_time);
            holder.root = (LinearLayout) convertView.findViewById(R.id.scroll_news_rootll);
            convertView.setTag(holder);
        }else{
            holder=(ViewHolder)convertView.getTag();
        }
        if(position == 0){
            holder.root.setPadding(30,20,0,30);
        }else{
            holder.root.setPadding(10,20,0,30);
        }
        Glide.with(mContext).load(list.get(position).getImgs().get(0)).crossFade().into((ImageView)holder.mImage);
        holder.mTitle.setText(list.get(position).getTitle());
        holder.priasecount.setText(list.get(position).getPraisecount());
        holder.fabutime.setText(list.get(position).getUpdateTime());
        return convertView;
    }

    private static class ViewHolder {
        private CardView cardview;
        private TextView mTitle ;
        private ImageView mImage;
        private TextView priasecount;
        private TextView fabutime;
        private LinearLayout root;
    }
}